﻿//------------------------------------------------------------------------------
// 创建标识: Copyright (C) 2008 Socansoft.com 版权所有

// 创建描述: SocanCode代码生成器自动创建于 2008-9-8 11:32:58
//
// 功能描述: 
//
// 修改标识: 
// 修改描述: 
//------------------------------------------------------------------------------

using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using IDAL;
using DBUtility;
using System.Collections;
using System.Collections.Generic;

namespace SQLServerDAL
{
    /// <summary>
    /// 数据访问类 ORDERDETAIL
    /// </summary>
    public class ORDERDETAIL : IORDERDETAIL
    {
        public ORDERDETAIL()
        { }

        #region  成员方法
        /// <summary>
        /// 增加一条数据

        /// </summary>
        public string Add(Model.ORDERDETAIL model)
        {
            int rowsAffected;
            SqlParameter[] parameters = {
                    new SqlParameter("@OD_ID", SqlDbType.VarChar,20),
                    new SqlParameter("@OD_DETAILID", SqlDbType.VarChar,20),
                    new SqlParameter("@OD_CMDCODE", SqlDbType.VarChar,20),
                    new SqlParameter("@OD_COLORCODE", SqlDbType.VarChar,6),
                    new SqlParameter("@OD_SIZECODE", SqlDbType.VarChar,6),
                    new SqlParameter("@OD_QTY", SqlDbType.Decimal),
                    new SqlParameter("@OD_SENDQTY", SqlDbType.Decimal),
                    new SqlParameter("@OD_SPRICE", SqlDbType.Decimal),
                    new SqlParameter("@OD_DISC", SqlDbType.Decimal),
                    new SqlParameter("@OD_APRICE", SqlDbType.Decimal),
                    new SqlParameter("@OD_SAMT", SqlDbType.Decimal),
                    new SqlParameter("@OD_AAMT", SqlDbType.Decimal),
                    new SqlParameter("@OD_NOTE", SqlDbType.VarChar,200),
                    new SqlParameter("@OD_FIELD1", SqlDbType.VarChar,20),
                    new SqlParameter("@OD_FIELD2", SqlDbType.VarChar,20),
                    new SqlParameter("@OD_SPPRICE", SqlDbType.Int),
                    new SqlParameter("@OD_GIFT", SqlDbType.Int),
                    new SqlParameter("@OD_ITGBUY", SqlDbType.Int),
                    new SqlParameter("@OD_ITGPRICE", SqlDbType.Decimal),
                    new SqlParameter("@OD_ITG", SqlDbType.Decimal),
                    new SqlParameter("@OD_ADDITG", SqlDbType.Decimal),
                    new SqlParameter("@OD_WEIGHT", SqlDbType.Decimal),
                    new SqlParameter("@OD_OFFER", SqlDbType.Int),
                    new SqlParameter("@OD_OFFERTYPE", SqlDbType.VarChar,20),
                    new SqlParameter("@OD_OFFERID", SqlDbType.VarChar,20),
                    new SqlParameter("@OD_OFFERNO", SqlDbType.VarChar,20)
            };
            parameters[0].Value = model.OD_ID;
            parameters[1].Value = model.OD_DETAILID;
            parameters[2].Value = model.OD_CMDCODE;
            parameters[3].Value = model.OD_COLORCODE;
            parameters[4].Value = model.OD_SIZECODE;
            parameters[5].Value = model.OD_QTY;
            parameters[6].Value = model.OD_SENDQTY;
            parameters[7].Value = model.OD_SPRICE;
            parameters[8].Value = model.OD_DISC;
            parameters[9].Value = model.OD_APRICE;
            parameters[10].Value = model.OD_SAMT;
            parameters[11].Value = model.OD_AAMT;

            if (model.OD_NOTE != null)
                parameters[12].Value = model.OD_NOTE;
            else
                parameters[12].Value = DBNull.Value;


            if (model.OD_FIELD1 != null)
                parameters[13].Value = model.OD_FIELD1;
            else
                parameters[13].Value = DBNull.Value;


            if (model.OD_FIELD2 != null)
                parameters[14].Value = model.OD_FIELD2;
            else
                parameters[14].Value = DBNull.Value;

            parameters[15].Value = model.OD_SPPRICE;
            parameters[16].Value = model.OD_GIFT;
            parameters[17].Value = model.OD_ITGBUY;
            parameters[18].Value = model.OD_ITGPRICE;
            parameters[19].Value = model.OD_ITG;
            parameters[20].Value = model.OD_ADDITG;
            parameters[21].Value = model.OD_WEIGHT;
            parameters[22].Value = model.OD_OFFER;

            if (model.OD_OFFERTYPE != null)
                parameters[23].Value = model.OD_OFFERTYPE;
            else
                parameters[23].Value = DBNull.Value;


            if (model.OD_OFFERID != null)
                parameters[24].Value = model.OD_OFFERID;
            else
                parameters[24].Value = DBNull.Value;


            if (model.OD_OFFERNO != null)
                parameters[25].Value = model.OD_OFFERNO;
            else
                parameters[25].Value = DBNull.Value;



            SqlHelper.RunProcedure(SqlHelper.LocalSqlServer, "sp_ORDERDETAIL_ADD", parameters, out rowsAffected);

            if (rowsAffected > 0)
                return model.OD_ID;
            else
                return null;
        }
        /// <summary>
        /// 增加一条数据

        /// </summary>
        public string Add(Model.ORDERDETAIL model,SqlTransaction tran)
        {
            int rowsAffected;
            SqlParameter[] parameters = {
                    new SqlParameter("@OD_ID", SqlDbType.VarChar,20),
                    new SqlParameter("@OD_DETAILID", SqlDbType.VarChar,20),
                    new SqlParameter("@OD_CMDCODE", SqlDbType.VarChar,20),
                    new SqlParameter("@OD_COLORCODE", SqlDbType.VarChar,6),
                    new SqlParameter("@OD_SIZECODE", SqlDbType.VarChar,6),
                    new SqlParameter("@OD_QTY", SqlDbType.Decimal),
                    new SqlParameter("@OD_SENDQTY", SqlDbType.Decimal),
                    new SqlParameter("@OD_SPRICE", SqlDbType.Decimal),
                    new SqlParameter("@OD_DISC", SqlDbType.Decimal),
                    new SqlParameter("@OD_APRICE", SqlDbType.Decimal),
                    new SqlParameter("@OD_SAMT", SqlDbType.Decimal),
                    new SqlParameter("@OD_AAMT", SqlDbType.Decimal),
                    new SqlParameter("@OD_NOTE", SqlDbType.VarChar,200),
                    new SqlParameter("@OD_FIELD1", SqlDbType.VarChar,20),
                    new SqlParameter("@OD_FIELD2", SqlDbType.VarChar,20),
                    new SqlParameter("@OD_SPPRICE", SqlDbType.Int),
                    new SqlParameter("@OD_GIFT", SqlDbType.Int),
                    new SqlParameter("@OD_ITGBUY", SqlDbType.Int),
                    new SqlParameter("@OD_ITGPRICE", SqlDbType.Decimal),
                    new SqlParameter("@OD_ITG", SqlDbType.Decimal),
                    new SqlParameter("@OD_ADDITG", SqlDbType.Decimal),
                    new SqlParameter("@OD_WEIGHT", SqlDbType.Decimal),
                    new SqlParameter("@OD_OFFER", SqlDbType.Int),
                    new SqlParameter("@OD_OFFERTYPE", SqlDbType.VarChar,20),
                    new SqlParameter("@OD_OFFERID", SqlDbType.VarChar,20),
                    new SqlParameter("@OD_OFFERNO", SqlDbType.VarChar,20)
            };
            parameters[0].Value = model.OD_ID;
            parameters[1].Value = model.OD_DETAILID;
            parameters[2].Value = model.OD_CMDCODE;
            parameters[3].Value = model.OD_COLORCODE;
            parameters[4].Value = model.OD_SIZECODE;
            parameters[5].Value = model.OD_QTY;
            parameters[6].Value = model.OD_SENDQTY;
            parameters[7].Value = model.OD_SPRICE;
            parameters[8].Value = model.OD_DISC;
            parameters[9].Value = model.OD_APRICE;
            parameters[10].Value = model.OD_SAMT;
            parameters[11].Value = model.OD_AAMT;

            if (model.OD_NOTE != null)
                parameters[12].Value = model.OD_NOTE;
            else
                parameters[12].Value = DBNull.Value;


            if (model.OD_FIELD1 != null)
                parameters[13].Value = model.OD_FIELD1;
            else
                parameters[13].Value = DBNull.Value;


            if (model.OD_FIELD2 != null)
                parameters[14].Value = model.OD_FIELD2;
            else
                parameters[14].Value = DBNull.Value;

            parameters[15].Value = model.OD_SPPRICE;
            parameters[16].Value = model.OD_GIFT;
            parameters[17].Value = model.OD_ITGBUY;
            parameters[18].Value = model.OD_ITGPRICE;
            parameters[19].Value = model.OD_ITG;
            parameters[20].Value = model.OD_ADDITG;
            parameters[21].Value = model.OD_WEIGHT;
            parameters[22].Value = model.OD_OFFER;

            if (model.OD_OFFERTYPE != null)
                parameters[23].Value = model.OD_OFFERTYPE;
            else
                parameters[23].Value = DBNull.Value;


            if (model.OD_OFFERID != null)
                parameters[24].Value = model.OD_OFFERID;
            else
                parameters[24].Value = DBNull.Value;


            if (model.OD_OFFERNO != null)
                parameters[25].Value = model.OD_OFFERNO;
            else
                parameters[25].Value = DBNull.Value;


            rowsAffected = DBHelper.ExecuteNonQuery(tran, "sp_ORDERDETAIL_ADD", parameters, CommandType.StoredProcedure);
            //SqlHelper.RunProcedure(SqlHelper.LocalSqlServer, "sp_ORDERDETAIL_ADD", parameters, out rowsAffected);

            if (rowsAffected > 0)
                return model.OD_ID;
            else
                return null;
        }

        /// <summary>
        /// 更新一条数据

        /// </summary>
        public bool Update(Model.ORDERDETAIL model)
        {
            int rowsAffected;
            SqlParameter[] parameters = {
                    new SqlParameter("@OD_ID", SqlDbType.VarChar,20),
                    new SqlParameter("@OD_DETAILID", SqlDbType.VarChar,20),
                    new SqlParameter("@OD_CMDCODE", SqlDbType.VarChar,20),
                    new SqlParameter("@OD_COLORCODE", SqlDbType.VarChar,6),
                    new SqlParameter("@OD_SIZECODE", SqlDbType.VarChar,6),
                    new SqlParameter("@OD_QTY", SqlDbType.Int),
                    new SqlParameter("@OD_SENDQTY", SqlDbType.Int),
                    new SqlParameter("@OD_SPRICE", SqlDbType.Decimal),
                    new SqlParameter("@OD_DISC", SqlDbType.Decimal),
                    new SqlParameter("@OD_APRICE", SqlDbType.Decimal),
                    new SqlParameter("@OD_SAMT", SqlDbType.Decimal),
                    new SqlParameter("@OD_AAMT", SqlDbType.Decimal),
                    new SqlParameter("@OD_NOTE", SqlDbType.VarChar,200),
                    new SqlParameter("@OD_FIELD1", SqlDbType.VarChar,20),
                    new SqlParameter("@OD_FIELD2", SqlDbType.VarChar,20),
                    new SqlParameter("@OD_SPPRICE", SqlDbType.Int),
                    new SqlParameter("@OD_GIFT", SqlDbType.Int),
                    new SqlParameter("@OD_ITGBUY", SqlDbType.Int),
                    new SqlParameter("@OD_ITGPRICE", SqlDbType.Decimal),
                    new SqlParameter("@OD_ITG", SqlDbType.Decimal),
                    new SqlParameter("@OD_ADDITG", SqlDbType.Decimal),
                    new SqlParameter("@OD_WEIGHT", SqlDbType.Decimal),
                    new SqlParameter("@OD_OFFER", SqlDbType.Int),
                    new SqlParameter("@OD_OFFERTYPE", SqlDbType.VarChar,20),
                    new SqlParameter("@OD_OFFERID", SqlDbType.VarChar,20),
                    new SqlParameter("@OD_OFFERNO", SqlDbType.VarChar,20)
            };
            parameters[0].Value = model.OD_ID;
            parameters[1].Value = model.OD_DETAILID;
            parameters[2].Value = model.OD_CMDCODE;
            parameters[3].Value = model.OD_COLORCODE;
            parameters[4].Value = model.OD_SIZECODE;
            parameters[5].Value = model.OD_QTY;
            parameters[6].Value = model.OD_SENDQTY;
            parameters[7].Value = model.OD_SPRICE;
            parameters[8].Value = model.OD_DISC;
            parameters[9].Value = model.OD_APRICE;
            parameters[10].Value = model.OD_SAMT;
            parameters[11].Value = model.OD_AAMT;

            if (model.OD_NOTE != null)
                parameters[12].Value = model.OD_NOTE;
            else
                parameters[12].Value = DBNull.Value;


            if (model.OD_FIELD1 != null)
                parameters[13].Value = model.OD_FIELD1;
            else
                parameters[13].Value = DBNull.Value;


            if (model.OD_FIELD2 != null)
                parameters[14].Value = model.OD_FIELD2;
            else
                parameters[14].Value = DBNull.Value;

            parameters[15].Value = model.OD_SPPRICE;
            parameters[16].Value = model.OD_GIFT;
            parameters[17].Value = model.OD_ITGBUY;
            parameters[18].Value = model.OD_ITGPRICE;
            parameters[19].Value = model.OD_ITG;
            parameters[20].Value = model.OD_ADDITG;
            parameters[21].Value = model.OD_WEIGHT;
            parameters[22].Value = model.OD_OFFER;

            if (model.OD_OFFERTYPE != null)
                parameters[23].Value = model.OD_OFFERTYPE;
            else
                parameters[23].Value = DBNull.Value;


            if (model.OD_OFFERID != null)
                parameters[24].Value = model.OD_OFFERID;
            else
                parameters[24].Value = DBNull.Value;


            if (model.OD_OFFERNO != null)
                parameters[25].Value = model.OD_OFFERNO;
            else
                parameters[25].Value = DBNull.Value;


            SqlHelper.RunProcedure(SqlHelper.LocalSqlServer, "sp_ORDERDETAIL_Update", parameters, out rowsAffected);
            return rowsAffected > 0;
        }

        /// <summary>
        /// 删除一条数据

        /// </summary>
        public bool Delete(string OD_ID)
        {
            int rowsAffected;
            SqlParameter[] parameters = {
                    new SqlParameter("@OD_ID", SqlDbType.VarChar,20)};
            parameters[0].Value = OD_ID;

            return ((int)SqlHelper.RunProcedureExecuteScalar(SqlHelper.LocalSqlServer, "sp_ORDERDETAIL_Delete", parameters)>0);
        }

        /// <summary>
        /// 是否存在该记录

        /// </summary>
        public bool Exists(string OD_ID)
        {
            int rowsAffected;
            SqlParameter[] parameters = {
                    new SqlParameter("@OD_ID", SqlDbType.VarChar,20)};
            parameters[0].Value = OD_ID;
            return SqlHelper.RunProcedure(SqlHelper.LocalSqlServer, "sp_ORDERDETAIL_Exists", parameters, out rowsAffected) == 1;
        }

        /// <summary>
        /// 得到一个对象实体

        /// </summary>
        public Model.ORDERDETAIL GetModel(string OD_ID)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@OD_ID", SqlDbType.VarChar,20)};
            parameters[0].Value = OD_ID;
            DataSet ds = SqlHelper.RunProcedure(SqlHelper.LocalSqlServer, "sp_ORDERDETAIL_GetModel", parameters, "ds");
            if (ds.Tables[0].Rows.Count > 0)
            {
                DataRow r = ds.Tables[0].Rows[0];
                return GetModel(r);
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获取泛型数据列表
        /// </summary>
        public IList<Model.ORDERDETAIL> GetList()
        {
            SqlParameter[] parameters ={ };
            DataSet ds = SqlHelper.RunProcedure(SqlHelper.LocalSqlServer, "sp_ORDERDETAIL_GetList", parameters, "ds");
            return GetList(ds);
        }

        /// <summary>
        /// 分页获取泛型数据列表
        /// </summary>
        public IList<Model.ORDERDETAIL> GetList(int pageSize, int pageIndex, string fldSort, bool sort, string strCondition, out int pageCount, out int count)
        {
            string strSql;
            DataSet ds = SqlHelper.PageList(SqlHelper.LocalSqlServer, "[ORDERDETAIL]", null, pageSize, pageIndex, fldSort, sort, strCondition, "OD_ID", false, out pageCount, out count, out strSql);
            return GetList(ds);
        }

        /// <summary>
        /// 更新订单明细后接着更新订单主单
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="orderDetailId"></param>
        /// <param name="quantity"></param>
        /// <param name="amount"></param>
        /// <param name="notes"></param>
        /// <returns></returns>
        public int UpdateOrderDetailAndOrderMain(string orderId, string orderDetailId, decimal quantity, decimal amount, string notes)
        {
            SqlParameter[] parameters = 
                {
                    SqlHelper.MakeInParam("@OD_QTY",SqlDbType.Decimal,8,quantity),
                    SqlHelper.MakeInParam("@OD_AAMT",SqlDbType.Decimal,8,amount),
                    SqlHelper.MakeInParam("@OD_NOTE",SqlDbType.VarChar,200,notes),
                    SqlHelper.MakeInParam("@OD_ID",SqlDbType.VarChar,20,orderId),
                    SqlHelper.MakeInParam("@OD_DETAILID",SqlDbType.VarChar,20,orderDetailId)
                };
            return (int)SqlHelper.RunProcedureExecuteScalar(SqlHelper.LocalSqlServer, "UpdateOrderDetailAndOrderMain", parameters);
        }

        /// <summary>
        /// 根据订单号获取订单明细
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public DataSet GetOrderDetail(string where)
        {
            SqlParameter[] parameters = 
                {
                    SqlHelper.MakeInParam("@where",SqlDbType.VarChar,20,where)
                };
            return SqlHelper.RunProcedure(SqlHelper.LocalSqlServer, "SP_ORDERDETAIL_GetOrderDetail", parameters, "tblOrderDetail");
        }

        public DataSet GetOrderDetailById(string orderId, string detailId)
        {
            SqlParameter[] parameters = 
                {
                    SqlHelper.MakeInParam("@orderId",SqlDbType.VarChar,20,orderId),
                    SqlHelper.MakeInParam("@detailId",SqlDbType.VarChar,20,detailId)
                };
            return SqlHelper.RunProcedure(SqlHelper.LocalSqlServer, "SP_ORDERDETAIL_GetOrderDetailById", parameters, "tblOrderDetail");
        }

        /// <summary>
        /// 执行修改发货单的一系列操作
        /// </summary>
        /// <param name="sqlCommandArray"></param>
        /// <returns></returns>
        public bool UpdateOrderDetailAndOrderMain(string[] sqlCommandArray)
        {
            return SqlHelper.ExecuteNonQuery(SqlHelper.LocalSqlServer, sqlCommandArray);
        }

        #endregion

        /// <summary>
        /// 由一行数据得到一个实体

        /// </summary>
        private Model.ORDERDETAIL GetModel(DataRow r)
        {
            Model.ORDERDETAIL model = new Model.ORDERDETAIL();
            model.OD_ID = SqlHelper.GetString(r["OD_ID"]);
            model.OD_DETAILID = SqlHelper.GetString(r["OD_DETAILID"]);
            model.OD_CMDCODE = SqlHelper.GetString(r["OD_CMDCODE"]);
            model.OD_COLORCODE = SqlHelper.GetString(r["OD_COLORCODE"]);
            model.OD_SIZECODE = SqlHelper.GetString(r["OD_SIZECODE"]);
            model.OD_QTY = SqlHelper.GetDecimal(r["OD_QTY"]);
            model.OD_SENDQTY = SqlHelper.GetDecimal(r["OD_SENDQTY"]);
            model.OD_SPRICE = SqlHelper.GetDecimal(r["OD_SPRICE"]);
            model.OD_DISC = SqlHelper.GetDecimal(r["OD_DISC"]);
            model.OD_APRICE = SqlHelper.GetDecimal(r["OD_APRICE"]);
            model.OD_SAMT = SqlHelper.GetDecimal(r["OD_SAMT"]);
            model.OD_AAMT = SqlHelper.GetDecimal(r["OD_AAMT"]);
            model.OD_NOTE = SqlHelper.GetString(r["OD_NOTE"]);
            model.OD_FIELD1 = SqlHelper.GetString(r["OD_FIELD1"]);
            model.OD_FIELD2 = SqlHelper.GetString(r["OD_FIELD2"]);
            model.OD_SPPRICE = SqlHelper.GetInt(r["OD_SPPRICE"]);
            model.OD_GIFT = SqlHelper.GetInt(r["OD_GIFT"]);
            model.OD_ITGBUY = SqlHelper.GetInt(r["OD_ITGBUY"]);
            model.OD_ITGPRICE = SqlHelper.GetDecimal(r["OD_ITGPRICE"]);
            model.OD_ITG = SqlHelper.GetDecimal(r["OD_ITG"]);
            model.OD_ADDITG = SqlHelper.GetDecimal(r["OD_ADDITG"]);
            model.OD_WEIGHT = SqlHelper.GetDecimal(r["OD_WEIGHT"]);
            model.OD_OFFER = SqlHelper.GetInt(r["OD_OFFER"]);
            model.OD_OFFERTYPE = SqlHelper.GetString(r["OD_OFFERTYPE"]);
            model.OD_OFFERID = SqlHelper.GetString(r["OD_OFFERID"]);
            model.OD_OFFERNO = SqlHelper.GetString(r["OD_OFFERNO"]);
            return model;
        }

        /// <summary>
        /// 由数据集得到泛型数据列表
        /// </summary>
        private IList<Model.ORDERDETAIL> GetList(DataSet ds)
        {
            List<Model.ORDERDETAIL> l = new List<Model.ORDERDETAIL>();
            foreach (DataRow r in ds.Tables[0].Rows)
            {
                l.Add(GetModel(r));
            }
            return l;
        }

        /// <summary>
        /// 由订单编号取出商品明细
        /// </summary>
        public DataSet P_Order_GetProductMX(string orderid)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@orderid", SqlDbType.VarChar,20)};
            parameters[0].Value = orderid;

            return SqlHelper.RunProcedure(SqlHelper.LocalSqlServer, "P_Order_GetProductMX", parameters, "ds");
        }

        public DataSet GetOrderDetailByOrderId(string orderid)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@orderid", SqlDbType.VarChar,20)};
            parameters[0].Value = orderid;

            return SqlHelper.RunProcedure(SqlHelper.LocalSqlServer, "P_Order_GetOrderDetailByOrderId", parameters, "ds");
        }
        /// <summary>
        /// 更新订单商品明细数据
        /// </summary>
        public bool P_Order_UpdateProductMX(string orderid,string od_detailid,string color,string size,int sl,decimal zk)
        {
            SqlParameter[] p =
                {
                    SqlHelper.MakeInParam("@od_id",SqlDbType.VarChar,20,orderid), 
                    SqlHelper.MakeInParam("@od_detailid",SqlDbType.VarChar,20,od_detailid),
                    SqlHelper.MakeInParam("@od_colorcode",SqlDbType.VarChar,6,color),
                    SqlHelper.MakeInParam("@od_sizecode",SqlDbType.VarChar,6,size),
                    SqlHelper.MakeInParam("@sl",SqlDbType.Int,4,sl),
                    SqlHelper.MakeInParam("@od_spzk",SqlDbType.Decimal,9,zk)
                };

            return ((int)SqlHelper.RunProcedureExecuteScalar(SqlHelper.LocalSqlServer, "P_Order_UpdateProductMX", p)>0);
        }
        /// <summary>
        /// 添加订单商品明细数据
        /// </summary>
        public bool P_Order_InsertProductMX(string orderid, string od_cmdcode, string color, string size, int sl,decimal zk)
        {
            SqlParameter[] p =
                {
                    SqlHelper.MakeInParam("@od_id",SqlDbType.VarChar,20,orderid), 
                    SqlHelper.MakeInParam("@od_cmdcode",SqlDbType.VarChar,20,od_cmdcode),
                    SqlHelper.MakeInParam("@od_colorcode",SqlDbType.VarChar,6,color),
                    SqlHelper.MakeInParam("@od_sizecode",SqlDbType.VarChar,6,size),
                    SqlHelper.MakeInParam("@sl",SqlDbType.Int,4,sl),               
                    SqlHelper.MakeInParam("@zk",SqlDbType.Decimal,9,zk)
                };

            return ((int)SqlHelper.RunProcedureExecuteScalar(SqlHelper.LocalSqlServer, "P_Order_InsertProductMX", p) > 0);
        }
        /// <summary>
        /// 删除订单商品明细数据
        /// </summary>
        public bool P_Order_DeleteProductMX(string orderid, string od_detailid)
        {
            SqlParameter[] p =
                {
                    SqlHelper.MakeInParam("@od_id",SqlDbType.VarChar,20,orderid), 
                    SqlHelper.MakeInParam("@od_detailid",SqlDbType.VarChar,20,od_detailid)
                };

            return ((int)SqlHelper.RunProcedureExecuteScalar(SqlHelper.LocalSqlServer, "P_Order_DeleteProductMX", p) > 0);
        }


        public DataSet GetQtyAndWeightByOrderIdAndDetailId(string orderId, string detailId)
        {
            SqlParameter[] p =
                {
                    SqlHelper.MakeInParam("@orderId",SqlDbType.VarChar,20,orderId), 
                    SqlHelper.MakeInParam("@detailId",SqlDbType.VarChar,20,detailId)
                };

            return SqlHelper.RunProcedure(SqlHelper.LocalSqlServer, "SP_ORDERDETAIL_GetQtyAndWeightByOrderIdAndDetailId", p, "tbl");
        }

        public DataSet GetProductSalesStatistics(string type, string tableString, string insertString, string selectOrderDocString, string orderDocLeftJoinString, 
            string orderDocGroupByString, string selectReturnDocString, string returnDocLeftJoinString, string returnDocGroupByString, string orderDocWhere, string returnDocWhere)
        {
            SqlParameter[] p =
                {
                    SqlHelper.MakeInParam("@type",SqlDbType.VarChar,20,type), 
                    SqlHelper.MakeInParam("@tableString",SqlDbType.VarChar,200,tableString),
                    SqlHelper.MakeInParam("@insertString",SqlDbType.VarChar,200,insertString), 
                    SqlHelper.MakeInParam("@selectOrderDocString",SqlDbType.VarChar,200,selectOrderDocString),
                    SqlHelper.MakeInParam("@orderDocLeftJoinString",SqlDbType.VarChar,200,orderDocLeftJoinString), 
                    SqlHelper.MakeInParam("@orderDocGroupByString",SqlDbType.VarChar,200,orderDocGroupByString),
                    SqlHelper.MakeInParam("@selectReturnDocString",SqlDbType.VarChar,200,selectReturnDocString), 
                    SqlHelper.MakeInParam("@returnDocLeftJoinString",SqlDbType.VarChar,200,returnDocLeftJoinString),
                    SqlHelper.MakeInParam("@returnDocGroupByString",SqlDbType.VarChar,200,returnDocGroupByString), 
                    SqlHelper.MakeInParam("@orderDocWhere",SqlDbType.VarChar,8000,orderDocWhere),
                    SqlHelper.MakeInParam("@returnDocWhere",SqlDbType.VarChar,8000,returnDocWhere)
                };

            return SqlHelper.RunProcedure(SqlHelper.LocalSqlServer, "SP_ProductSalesStatistics", p, "tbl");
        }
    }
}
